package utils;

import bean.response.ResponseBean;
import bean.response.ResultEnum;

/**
 * 返回对象工具类
 * @author Seven
 * @date 2021/11/21
 */
public class ResultInfoUtil {
    /**
     * 请求出错返回
     * @return
     */
    public static ResponseBean buildError(){
        return build(ResultEnum.ERROR,null);
    }

    public static ResponseBean buildError(ResultEnum resultEnum){
        return build(resultEnum, null);
    }

    public static ResponseBean buildError(ResultEnum resultEnum, String msg){
        return build(resultEnum.getCode(), msg, null);
    }

    public static ResponseBean buildError(String msg){
        return build(ResultEnum.BAD_REQUEST, msg);
    }

    /**
     * 请求成功返回
     * @return
     */
    public static ResponseBean buildSuccess(){
        return build(ResultEnum.OK,null);
    }
    public static ResponseBean buildSuccess(ResultEnum resultEnum, Object data){
        return build(resultEnum, data);
    }
    public static ResponseBean buildSuccess(ResultEnum resultEnum, String msg){
        return build(resultEnum.getCode(), msg, null);
    }
    public static ResponseBean buildSuccess(ResultEnum resultEnum, String msg, Object data){
        return build(resultEnum.getCode(), msg, data);
    }
    public static ResponseBean buildSuccess(Object data){
        return build(ResultEnum.OK, data);
    }

    /**
     * 构建返回对象 方法1
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static ResponseBean build(Integer code, String msg, Object data){
        if (code == null){
            code = ResultEnum.OK.getCode();
        }
        if (msg == null){
            msg = ResultEnum.ERROR.getMessage();
        }
        return new ResponseBean(code,msg,data);
    }

    /**
     * 构建返回对象 方法2
     * @param resultEnum
     * @param data
     * @return
     */
    public static ResponseBean build(ResultEnum resultEnum, Object data){
        return new ResponseBean(resultEnum.getCode(), resultEnum.getMessage(), data);
    }

}
